﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Lamex.SIESystemManager.Calculate
{
    public class C_D51
    {
        public double GetD51(DataRow[] dr1, DataRow[] dr2)
        {
            double TD51 = 0;
            double D51_PEFilmPackaging = 0;
            double D51_CartonPackaging = 0;
            double D51_PaperPackaging = 0;
            double D51_BoardPackaging = 0;
            double D51_Board_Qty = 0;
            //单位工时
            double WD51_PEFilmPackaging = 0;
            double WD51_CartonPackaging = 0;
            double WD51_PaperPackaging = 0;
            double WD51_BoardPackaging = 0;
            double WD51_Board_Qty = 0;
            //附加工时
            double AD51_PEFilmPackaging = 0;
            double AD51_CartonPackaging = 0;
            double AD51_PaperPackaging = 0;
            double AD51_BoardPackaging = 0;
            double AD51_Board_Qty = 0;
            //获取数据库每个工序动作的单位工时和附加工时
            foreach (var drHours in dr2)
            {
                switch (drHours["OPERATIONAL_NAME"].ToString())
                {
                    case "PE包装柜桶":
                        WD51_PEFilmPackaging = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD51_PEFilmPackaging = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "PE包装板件":
                        WD51_CartonPackaging = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD51_CartonPackaging = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "纸箱包装柜子":
                        WD51_PaperPackaging = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD51_PaperPackaging = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "纸箱包装板件":
                        WD51_BoardPackaging = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD51_BoardPackaging = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                    case "板件数量":
                        WD51_Board_Qty = double.Parse(string.IsNullOrEmpty(drHours["UNIT_WORKHOURS"].ToString()) ? "0" : drHours["UNIT_WORKHOURS"].ToString());//单位工时
                        AD51_Board_Qty = double.Parse(string.IsNullOrEmpty(drHours["ATTACH_WORKHOURS"].ToString()) ? "0" : drHours["ATTACH_WORKHOURS"].ToString());//附加工时
                        break;
                   
                }
            }
            //特征值
            foreach (var drData in dr1)
            {
                D51_PEFilmPackaging = double.Parse(string.IsNullOrEmpty(drData["D51_PEFilmPackaging"].ToString()) ? "0" : drData["D51_PEFilmPackaging"].ToString());
                D51_CartonPackaging = double.Parse(string.IsNullOrEmpty(drData["D51_CartonPackaging"].ToString()) ? "0" : drData["D51_CartonPackaging"].ToString());
                D51_PaperPackaging = double.Parse(string.IsNullOrEmpty(drData["D51_PaperPackaging"].ToString()) ? "0" : drData["D51_PaperPackaging"].ToString());
                D51_BoardPackaging = double.Parse(string.IsNullOrEmpty(drData["D51_BoardPackaging"].ToString()) ? "0" : drData["D51_BoardPackaging"].ToString());
                D51_Board_Qty = double.Parse(string.IsNullOrEmpty(drData["D51_Board_Qty"].ToString()) ? "0" : drData["D51_Board_Qty"].ToString());
            }
            //工时计算
            //PE包装柜桶
            if (D51_PEFilmPackaging == 1)
                TD51 = D51_PEFilmPackaging * WD51_PEFilmPackaging;
            //PE包装板件
            else if (D51_CartonPackaging == 1)
                TD51 = D51_CartonPackaging * WD51_CartonPackaging;
            //纸箱包装柜子
            else if (D51_PaperPackaging == 1)
                TD51 = D51_PaperPackaging * WD51_PaperPackaging;
            else
            {
                TD51 = D51_PEFilmPackaging * WD51_PEFilmPackaging + D51_CartonPackaging * WD51_CartonPackaging +
                    D51_PaperPackaging * WD51_PaperPackaging + D51_BoardPackaging * WD51_BoardPackaging + D51_Board_Qty * WD51_Board_Qty;
            }
            return TD51;
        }
    }
}
